﻿Public Class fr_Loaithu
    Dim DS As New List(Of LoaiThu)
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If MessageBox.Show("Bạn muốn thoát!", "Thông Báo!", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
            Me.Close()
        End If

    End Sub


    Sub HienThi()
        DS = XL_LoaiThu.LayDS()
        LsvDS.Items.Clear()
        For i = 0 To DS.Count - 1
            Dim li As New ListViewItem(i + 1)
            li.Tag = DS(i)
            li.SubItems.Add(DS(i).Loai)
            LsvDS.Items.Add(li)
        Next
    End Sub


    Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        HienThi()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text <> "" Then
            Dim l As New LoaiThu()
            l.Loai = TextBox1.Text
            l.Xoa = False
            XL_LoaiThu.Them(l)
            HienThi()
            MessageBox.Show(l.ID.ToString())
        Else
            MessageBox.Show("Nhập loại cần thêm!", "Thông báo")
        End If

    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If LsvDS.SelectedItems.Count > 0 Then
            Dim l As LoaiThu = LsvDS.SelectedItems(0).Tag
            If Not TextBox1.Text Is Nothing Then
                l.Loai = TextBox1.Text
                XL_LoaiThu.CapNhat(l)
                HienThi()
            Else
                MessageBox.Show("Nhập tên cần sửa!", "Thông báo")
            End If
        Else
            MessageBox.Show("Chọn loại cần sửa!", "Thông báo")
        End If
    End Sub

    Private Sub LsvDS_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LsvDS.SelectedIndexChanged
        If LsvDS.SelectedItems.Count > 0 Then
            Dim l As LoaiThu = LsvDS.SelectedItems(0).Tag
            TextBox1.Text = l.Loai
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If LsvDS.SelectedItems.Count > 0 Then
            If MessageBox.Show("Bạn muốn xóa dữ liệu này ?", "Thông Báo!", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
                Dim l As LoaiThu = LsvDS.SelectedItems(0).Tag
                XL_LoaiThu.Xoa(l)
                HienThi()
            End If
        Else
            MessageBox.Show("Chọn loại cần xóa!", "Thông báo")
        End If
    End Sub
End Class